
package com.hnucm.chapter3_2;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hnucm.chapter3_2.view.SwipeDeleteRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class SwipeActivity extends AppCompatActivity {

    SwipeDeleteRecyclerView recyclerView;
    MyAdapter adapter;
    List list=new ArrayList();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_swipe);

        for(int i=0;i<10;++i){
            list.add("文本"+i);
        }

        recyclerView=findViewById(R.id.recycler_view);
        adapter=new MyAdapter();
        recyclerView.setAdapter(adapter);
        recyclerView.setStateCallback(new SwipeDeleteRecyclerView.StateCallback() {
            @Override
            public void dragEnable(boolean enable) {
                return;
            }
        });
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }


    public class MyAdapter extends RecyclerView.Adapter<MyViewHolder>{

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view= LayoutInflater.from(SwipeActivity.this).inflate(R.layout.item_swiperecyclerview,parent,false);
            return new MyViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            holder.textView.setText(list.get(position).toString());
        }

        @Override
        public int getItemCount() {
            return list.size();
        }
    }
    public class MyViewHolder extends RecyclerView.ViewHolder{

        TextView textView;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            textView=itemView.findViewById(R.id.textView);
        }
    }
}